home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / infowdw.pas < prev    next >
Pascal/Delphi Source File  |  1991-04-22  |  4KB  |  129 lines

  1. Program InfoWindow;
  2. (*  This is an example of a modeless object used to display status information
  3.     during the execution of an application.  The object tStatusText represents
  4.     a status line that is updated dynamically during processing.  This example
  5.     has only one line of text, but by instantiating multiple instances of
  6.     tStatusText, it would be possible to have more that one line.  This exampe
  7.     is based on a suggestion by Ted Husted  *)
  8.  
  9. Uses App, objects,views,Dialogs,crt;
  10. Type
  11.   mApp = object(tApplication)
  12.     Constructor Init;               {just to put up a desktop}
  13.   End;
  14.  
  15.  pstatustext=^tstatustext;          {pointer to an object}
  16.  tstatustext=object(tstatictext)    {object that contains the status line}
  17.   procedure newtext(n: Integer);    {that will be updated during processing}
  18.  end;
  19.  
  20.  {-- tInfoBox is the actual window that will contains the status line that
  21.      will be updated during processing.  It is initialzed and controlled
  22.      by the tStatusBox object. --}
  23.  
  24.  pInfoBox = ^tInfoBox;
  25.  tInfoBox = object(tWindow)
  26.    constructor Init(wTitle: string; wMsg: String;nx,ny,mx,my: Integer);
  27.  end;
  28.  
  29.  {-- tStatusBox controls the updating of the infoBox status line --}
  30.  pStatusBox = ^tStatusBox;
  31.  tStatusBox = object(tInfoBox)
  32.    statusLine: pStatusText;
  33.    constructor Init(wTitle: string;promptLine: string;nx,ny,mx,my: Integer);
  34.    destructor  Done; virtual;
  35.    Procedure changeStatusLine(newStat: integer);
  36.  End;
  37.  
  38. Var
  39.   InfoBox: pInfoBox;
  40.   statusBox: pStatusBox;
  41.   m: mApp;
  42.  
  43. CONSTRUCTOR tStatusBox.Init(wTitle: string;
  44.                             promptLine: string;
  45.                             nx,ny,mx,my: Integer);
  46. var
  47.   r: tRect;
  48. begin
  49.   tInfoBox.Init(wTitle,PromptLine,nx,ny,mx,my);  {initializes the infoBox object}
  50.   r.Assign(23,2,31,3);
  51.   statusLine := new(pStatusText,Init(r,' '));     {initializes the statusLine object}
  52.   insert(statusLine);                             {and inserts it into infoBox}
  53. end;
  54.  
  55. PROCEDURE tStatusBox.ChangeStatusLine;
  56. Begin
  57.   statusLine^.newText(newStat);             {changes the value of the statusLine}
  58. end;
  59.  
  60. Destructor tStatusBox.Done;
  61. Begin
  62.   dispose(statusLine,Done);     {disposes of allocated memory}
  63.   tInfoBox.Done;
  64. end;
  65.  
  66. procedure tstatustext.newtext(n: Integer);
  67. var
  68.   s: string;
  69.  
  70. begin
  71.  str(n,s);          {strings the passed integer value}
  72.  if (text <> nil) then   {Checks to see if the instance variable text exists}
  73.    disposeStr(text);     {if it does, it is disposed of. This is VERY IMPORTANT!}
  74.  text:=newstr(s);        {Allocates memory for the text instance variable}
  75.  drawView;               {redraws the status line}
  76. end;
  77.  
  78. CONSTRUCTOR tInfoBox.Init;
  79. {-- Initializes an information window --}
  80. var
  81.   r: tRect;
  82.   control: pView;
  83.  
  84. begin
  85.   r.Assign(nx,ny,mx,my);
  86.   tWindow.Init(r,wTitle,0);
  87.   options := Options or ofCentered;
  88.   palette := wpGrayWindow;
  89.   flags := $00;
  90.   r.assign(2,2,35,3);
  91.   Control := new(pStaticText,Init(r,wMsg));
  92.   insert(control);
  93. End;
  94.  
  95. PROCEDURE showStatusBox(wTitle,prompt: string);
  96. {-- Instantiates statusBox and inserts it into the deskTop --}
  97. Begin
  98.   statusBox := new(pStatusBox,Init(wTitle,prompt,0,0,41,6));
  99.   desktop^.Insert(statusBox);
  100. end;
  101.  
  102. PROCEDURE ChangeStatusBox(newNum: Integer);
  103. Begin
  104.   StatusBox^.ChangeStatusLine(newNum);
  105. End;
  106.  
  107. PROCEDURE removeStatusBox;
  108. Begin
  109.   dispose(StatusBox,Done);
  110. end;
  111.  
  112. Constructor mApp.Init;
  113. Var
  114.   count: Integer;
  115.  
  116. Begin
  117.   tapplication.Init;
  118.    showStatusBox('Processing Deletions','Processing Record:');
  119.    for count := 1 to 5000 do begin
  120.      ChangeStatusBox(count);
  121.      delay(1);
  122.    End;
  123.    RemoveStatusBox;
  124. End;
  125.  
  126. Begin
  127.   m.Init;
  128.   m.Done;
  129. End.